package com.feifan.monthhelper.ui.guide;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.StringUtils;
import com.feifan.monthhelper.R;
import com.feifan.monthhelper.constant.Constant;
import com.feifan.monthhelper.ui.base.BaseActivity;
import com.feifan.monthhelper.utils.CommonDialogUtils;
import com.feifan.monthhelper.utils.SPUtils;
import com.feifan.monthhelper.wedget.DoubleClickListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import cn.qqtheme.framework.picker.OptionPicker;

public class Step3Activity extends BaseActivity {

    @BindView(R.id.rl_title)
    RelativeLayout rlTitle;
    @BindView(R.id.tv_menses_span_days)
    TextView tvMensesSpanDays;
    @BindView(R.id.iv_pre)
    ImageView ivPre;
    @BindView(R.id.iv_next)
    ImageView ivNext;

    private List<String> MensesSpanDays;

    private OptionPicker.OnOptionPickListener optionPickListener = new OptionPicker.OnOptionPickListener() {
        @Override
        public void onOptionPicked(int index, String item) {
            if (tvMensesSpanDays != null) {
                tvMensesSpanDays.setText(item);
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View getTitleView() {
        return rlTitle;
    }

    @Override
    protected void initData() {
        MensesSpanDays = new ArrayList<>();
        for(int i=20;i<41;i++) {
            MensesSpanDays.add(i+"天");
        }
    }

    @Override
    protected void initView() {
        tvMensesSpanDays.setText(SPUtils.getInstance().getString(Constant.ShareKey.MENSTRUAL_CYCLE_SPAN_DAYS));

        ivPre.setOnClickListener(new DoubleClickListener() {
            @Override
            public void doOnClick(View view) {
                finish();
            }
        });
        ivNext.setOnClickListener(new DoubleClickListener() {
            @Override
            public void doOnClick(View view) {
                String days = tvMensesSpanDays.getText().toString().trim();
                if(StringUtils.isEmpty(days)) {
                    showToast(R.string.menses_span_days_is_null);
                    return;
                }
                SPUtils.getInstance().put(Constant.ShareKey.MENSTRUAL_CYCLE_SPAN_DAYS, days);
                startActivity(new Intent(getApplication(), Step4Activity.class));
            }
        });
        tvMensesSpanDays.setOnClickListener(new DoubleClickListener() {
            @Override
            public void doOnClick(View view) {
                CommonDialogUtils.ShowOptionPicker(Step3Activity.this, MensesSpanDays, tvMensesSpanDays.getText().toString().trim(), optionPickListener);
            }
        });
    }

    @Override
    protected int setContentLayout() {
        return R.layout.activity_step3;
    }
}
